home *** CD-ROM | disk | FTP | other *** search
/ Champak 66 / Vol 66.iso / games / datedres.swf / scripts / CSnow_.as
Text File  |  2013-04-24  |  3KB  |  123 lines

  1. function CSnow()
  2. {
  3.    this.Init();
  4. }
  5. CSnow.prototype = new MovieClip();
  6. CSnow.prototype.Init = function()
  7. {
  8.    if(this._width < 100)
  9.    {
  10.       this._width = 100;
  11.    }
  12.    if(this._height < 100)
  13.    {
  14.       this._height = 100;
  15.    }
  16.    this.m_nRight = this._width;
  17.    this.m_nBottom = this._height;
  18.    this.ins_Mask._width = this._width;
  19.    this.ins_Mask._height = this._height;
  20.    this._xscale = 100;
  21.    this._yscale = 100;
  22.    this.setMask(this.ins_Mask);
  23.    this.ConfirmValue();
  24.    this.CreateSnow();
  25. };
  26. CSnow.prototype.ConfirmValue = function()
  27. {
  28.    if(this.m_nSnowSpeed <= 0)
  29.    {
  30.       this.m_nSnowSpeed = 5;
  31.    }
  32.    if(this.m_nSnowSpeed > 100)
  33.    {
  34.       this.m_nSnowSpeed = 100;
  35.    }
  36.    if(this.m_nLeftWind > 10)
  37.    {
  38.       this.m_nLeftWind = 10;
  39.    }
  40.    if(this.m_nRightWind > 10)
  41.    {
  42.       this.m_nRightWind = 10;
  43.    }
  44. };
  45. CSnow.prototype.CreateSnow = function()
  46. {
  47.    this.attachMovie(this.m_strSnowMovie,"Snow_Test",1);
  48.    if(this.Snow_Test == undefined)
  49.    {
  50.       this.m_strSnowMovie = "DefaultSnow";
  51.    }
  52.    this.Snow_Test.removeMovieClip();
  53.    i = 1;
  54.    while(i < this.m_nSnowMax)
  55.    {
  56.       this.attachMovie(this.m_strSnowMovie,"Snow" + i,i);
  57.       eval("this.Snow" + i)._x = -1;
  58.       eval("this.Snow" + i).onEnterFrame = this.SnowOnEnterFrame;
  59.       i++;
  60.    }
  61. };
  62. CSnow.prototype.SetSnow = function(snowMax)
  63. {
  64.    if(this.m_nSnowMax > snowMax)
  65.    {
  66.       i = snowMax;
  67.       while(i < this.m_nSnowMax)
  68.       {
  69.          eval("this.Snow" + i).removeMovieClip();
  70.          i++;
  71.       }
  72.    }
  73.    else
  74.    {
  75.       i = this.m_nSnowMax;
  76.       while(i < snowMax)
  77.       {
  78.          this.attachMovie(this.m_strSnowMovie,"Snow" + i,i);
  79.          eval("this.Snow" + i)._x = -1;
  80.          eval("this.Snow" + i).onEnterFrame = this.SnowOnEnterFrame;
  81.          i++;
  82.       }
  83.    }
  84.    this.m_nSnowMax = snowMax;
  85. };
  86. CSnow.prototype.SetSpeed = function(Speed)
  87. {
  88.    this.m_nSnowSpeed = Speed;
  89.    this.ConfirmValue();
  90. };
  91. CSnow.prototype.SetLeftWind = function(leftWind)
  92. {
  93.    this.m_nLeftWind = leftWind;
  94.    this.ConfirmValue();
  95. };
  96. CSnow.prototype.SetRightWind = function(rightWind)
  97. {
  98.    this.m_nRightWind = rightWind;
  99.    this.ConfirmValue();
  100. };
  101. CSnow.prototype.SnowOnEnterFrame = function()
  102. {
  103.    if(this._x <= 0 or this._x > this._parent.m_nRight or this._y > this._parent.m_nBottom)
  104.    {
  105.       this._parent.ResetSnowEntty(this);
  106.       return undefined;
  107.    }
  108.    this._x += this.t_nSpeedX;
  109.    this._y += this.t_nSpeedY;
  110. };
  111. CSnow.prototype.ResetSnowEntty = function(obj)
  112. {
  113.    var sz = random(120) - 10;
  114.    obj._xscale = sz;
  115.    obj._yscale = sz;
  116.    obj._x = random(this.m_nRight) + 1;
  117.    obj._y = random(this.m_nBottom) + 1;
  118.    obj.t_nSpeedX = this.m_nRightWind + random(this.m_nRightWind) - (this.m_nLeftWind + random(this.m_nLeftWind));
  119.    obj.t_nSpeedY = 2 + this.m_nSnowSpeed * sz * 0.01;
  120.    obj.gotoAndPlay(1);
  121. };
  122. Object.registerClass("CSnow_",CSnow);
  123.